I'm trying put a interger to a text attribute. Can't seem to figure out how to convert interger to text or string. Any help would be appreciated. Thanks!
|
Re: convert int to text or string
Here is the code...
Module m = current
Object o
string objText
if ( null m )
{ //
ack "Please open a module first."
halt
}
for o in m do {
objText = o."SRC_ID"
if (isValidInt(objText))
if(intOf(objText)>0)
{
int src_id = intOf(objText)-55
o."SRC_ID" = src_id //ERROR: expected int attribute
}
}
|
Re: convert int to text or string DOORS_USER - Fri May 14 12:10:24 EDT 2010
Here is the code...
Module m = current
Object o
string objText
if ( null m )
{ //
ack "Please open a module first."
halt
}
for o in m do {
objText = o."SRC_ID"
if (isValidInt(objText))
if(intOf(objText)>0)
{
int src_id = intOf(objText)-55
o."SRC_ID" = src_id //ERROR: expected int attribute
}
}
Hi DOORS USER!
Module m = current
Object o
string objText
if ( null m )
{ //
ack "Please open a module first."
halt
}
for o in m do {
objText = o."SRC_ID"
if (isValidInt(objText))
if(intOf(objText)>0)
{
int src_id = intOf(objText)-55
o."SRC_ID" = src_id "" //ERROR: expected int attribute
/* Concatenation with an empty string */
}
}
|
Re: convert int to text or string Looks to me like your SRC_ID attribute should be type 'Integer', in which case you read it into an int variable, subtract 55, and put it back.
|
Re: convert int to text or string DOORS_USER - Fri May 14 12:10:24 EDT 2010
Here is the code...
Module m = current
Object o
string objText
if ( null m )
{ //
ack "Please open a module first."
halt
}
for o in m do {
objText = o."SRC_ID"
if (isValidInt(objText))
if(intOf(objText)>0)
{
int src_id = intOf(objText)-55
o."SRC_ID" = src_id //ERROR: expected int attribute
}
}
You should also note that the isValidInt function does not behave as you would expect (if your string contains only of whitespaces) ... So you might want to put a check there ...
string s = " "
if (isValidInt s) {
print "Cewl, its valid!"
intOf s // argh, it isnt ... :-(
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: convert int to text or string Mathias Mamsch - Sat May 15 09:07:40 EDT 2010
You should also note that the isValidInt function does not behave as you would expect (if your string contains only of whitespaces) ... So you might want to put a check there ...
string s = " "
if (isValidInt s) {
print "Cewl, its valid!"
intOf s // argh, it isnt ... :-(
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Here's my two functions that do the conversions.
//***************
bool fIsValidInt(string InString)
{ // Is the string a valid positive or negative integer?
// InString must be digits, optionally preceded with a dash "-", e.g. "-123";
// must not have commas, e.g. "12,345".
// Developer's note: Null strings return false here, whereas "isValidInt" returns true.
if (null InString or !isValidInt(InString))
return(false)
else return(true)
} // end fIsValidInt()
//***************
bool fStringToInt(string InString, int &OutInt)
{ // Convert the InString to a valid Integer. Return whether it worked.
// Improper or null Strings return False and Zero
// Max int is about 10 digits (system limitation in DOORS v7.1)
if (!fIsValidInt(InString))
{ OutInt = 0
return(false)
}
else
{ OutInt = intOf(InString)
return(true)
}
} // end fStringToInt()
|